package controller

import (
	beego "github.com/beego/beego/v2/server/web"
	config2 "passwordBook/config"
	"passwordBook/util"
)

var configFilePath, _ = beego.AppConfig.String("commonConfigFilePath")

type ConfigController struct {
	BasicController
}

func (c *ConfigController) List() {
	config := util.ReadToml(configFilePath)
	c.Message.Data = config
	c.Message.Code = 200
	c.Message.Msg = "获取配置文件成功"
	c.JSONResp(c.Message)
}
func (c *ConfigController) Edit() {
	newConfig := config2.CommonConfig{}
	c.BindJSON(&newConfig)
	util.WriteToml(newConfig, configFilePath)
	c.Message.Data = newConfig
	c.Message.Code = 200
	c.Message.Msg = "修改配置文件成功"
	c.JSONResp(c.Message)

}
